<style>
.randTable tbody tr {background: #fff}
</style>
<script>
var shuffle = function(o){
    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
    return o;
};

$(document).ready(function(){

    $("#setBtn").click(function(){
        if (confirm('<?php echo  $this->translate("Are you sure adjust class order?")?>')){
            $("#adjustForm").submit();
        }
     });

    $("#randBtn").click(function(){
        var classVar = new Array();
        for(i=0; i<<?php echo $this->data["new_class_num"]?>;  i++)
            classVar[i] = i+1;
        var randInput = shuffle(classVar);
        $.each(randInput,function(i,v){
            var t = i+1;
            $("input[name='changeClass["+t+"]']").attr('value',v);
         });
      });

});
</script>
<form action="<?php echo  $this->route('save-class-order')?>" method="post" id="adjustForm" >
<table class="listTable randTable">
<thead>
<tr>
<th colspan="2">
電腦亂數編班 -- 班序調整
</th>
</tr>
</thead>
<tbody>
<tr>
<th>學年度年級</th>
<td>
<?php $gradeName = unserialize($this->School['length_name']);?>
<?php $arr = explode('-',$this->data['year_semester'])?>
<?php echo sprintf($this->translate('%d year %d semester %s'),$arr[0], $arr[1], $gradeName[$arr[2]])?>
</td>
</tr>
<tr>
<th> 班級數</th>
<td>
<ul>
<?php for($i=1; $i <  $this->data['new_class_num'] ; $i++):?>
<li>班序<?php echo  $i?> == 改為 == <input type="text" name="changeClass[<?php echo $i?>]" size="2" value="<?php echo $i?>" /> </li>
<?php endfor?>
</ul>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="button" id="randBtn" value="亂數調整" />
<input type="button" id="setBtn" value="寫入" />
<input type="hidden" id="sn"  name="sn" value="<?php echo $this->data['sn']?>"  />
</td>
</tr>
</tbody>
</table>
</form>
